]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
viewSelector: Take edge drag gesture into a separate file
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 5 Aug 2014 14:25:30 +0000 (16:25 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Sat, 30 Aug 2014 12:01:44 +0000 (14:01 +0200)
This may not be solely used by this code, so take the gesture action
code to its own separate file.

https://bugzilla.gnome.org/show_bug.cgi?id=735625

js/js-resources.gresource.xml
js/ui/edgeDragAction.js [new file with mode: 0644]
js/ui/viewSelector.js

index ffef87194eefe2c60387e4a3d0de9597e81b6676..c99189cfe2ef3eea1f7a66b590a526f14499b83d 100644 (file)
@@ -42,6 +42,7 @@
     <file>ui/dash.js</file>
     <file>ui/dateMenu.js</file>
     <file>ui/dnd.js</file>
+    <file>ui/edgeDragAction.js</file>
     <file>ui/endSessionDialog.js</file>
     <file>ui/environment.js</file>
     <file>ui/extensionDownloader.js</file>
diff --git a/js/ui/edgeDragAction.js b/js/ui/edgeDragAction.js
new file mode 100644 (file)
index 0000000..692da41
--- /dev/null
@@ -0,0 +1,78 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const Lang = imports.lang;
+const Signals = imports.signals;
+const Meta = imports.gi.Meta;
+const Clutter = imports.gi.Clutter;
+const St = imports.gi.St;
+
+const EDGE_THRESHOLD = 20;
+const DRAG_DISTANCE = 80;
+
+const EdgeDragAction = new Lang.Class({
+    Name: 'EdgeDragAction',
+    Extends: Clutter.GestureAction,
+
+    _init : function(side) {
+        this.parent();
+        this._side = side;
+        this.set_n_touch_points(1);
+
+        global.display.connect('grab-op-begin', Lang.bind(this, function() {
+            this.cancel();
+        }));
+    },
+
+    _getMonitorRect : function (x, y) {
+        let rect = new Meta.Rectangle({ x: x - 1, y: y - 1, width: 1, height: 1 });
+        let monitorIndex = global.screen.get_monitor_index_for_rect(rect);
+
+        return global.screen.get_monitor_geometry(monitorIndex);
+    },
+
+    vfunc_gesture_prepare : function(action, actor) {
+        if (this.get_n_current_points() == 0)
+            return false;
+
+        let [x, y] = this.get_press_coords(0);
+        let monitorRect = this._getMonitorRect(x, y);
+
+        return ((this._side == St.Side.LEFT && x < monitorRect.x + EDGE_THRESHOLD) ||
+                (this._side == St.Side.RIGHT && x > monitorRect.x + monitorRect.width - EDGE_THRESHOLD) ||
+                (this._side == St.Side.TOP && y < monitorRect.y + EDGE_THRESHOLD) ||
+                (this._side == St.Side.BOTTOM && y > monitorRect.y + monitorRect.height - EDGE_THRESHOLD));
+    },
+
+    vfunc_gesture_progress : function (action, actor) {
+        let [startX, startY] = this.get_press_coords(0);
+        let [x, y] = this.get_motion_coords(0);
+        let offsetX = Math.abs (x - startX);
+        let offsetY = Math.abs (y - startY);
+
+        if (offsetX < EDGE_THRESHOLD && offsetY < EDGE_THRESHOLD)
+            return true;
+
+        if ((offsetX > offsetY &&
+             (this._side == St.Side.TOP || this._side == St.Side.BOTTOM)) ||
+            (offsetY > offsetX &&
+             (this._side == St.Side.LEFT || this._side == St.Side.RIGHT))) {
+            this.cancel();
+            return false;
+        }
+
+        return true;
+    },
+
+    vfunc_gesture_end : function (action, actor) {
+        let [startX, startY] = this.get_press_coords(0);
+        let [x, y] = this.get_motion_coords(0);
+        let monitorRect = this._getMonitorRect(startX, startY);
+
+        if ((this._side == St.Side.TOP && y > monitorRect.y + DRAG_DISTANCE) ||
+            (this._side == St.Side.BOTTOM && y < monitorRect.y + monitorRect.height - DRAG_DISTANCE) ||
+            (this._side == St.Side.LEFT && x > monitorRect.x + DRAG_DISTANCE) ||
+            (this._side == St.Side.RIGHT && x < monitorRect.x + monitorRect.width - DRAG_DISTANCE))
+            this.emit('activated');
+    }
+});
+Signals.addSignalMethods(EdgeDragAction.prototype);
index 80c3035d4903f92e85531583b899718ae19a14c4..9b1c6047b74adc96dfe831f703ce1b6eea296495 100644 (file)
@@ -19,6 +19,7 @@ const Search = imports.ui.search;
 const ShellEntry = imports.ui.shellEntry;
 const Tweener = imports.ui.tweener;
 const WorkspacesView = imports.ui.workspacesView;
+const EdgeDragAction = imports.ui.edgeDragAction;
 
 const SHELL_KEYBINDINGS_SCHEMA = 'org.gnome.shell.keybindings';
 
@@ -49,77 +50,6 @@ function getTermsForSearchString(searchString) {
     return terms;
 }
 
-const EDGE_THRESHOLD = 20;
-const DRAG_DISTANCE = 80;
-
-const EdgeDragAction = new Lang.Class({
-    Name: 'EdgeDragAction',
-    Extends: Clutter.GestureAction,
-
-    _init : function(side) {
-        this.parent();
-        this._side = side;
-        this.set_n_touch_points(1);
-
-        global.display.connect('grab-op-begin', Lang.bind(this, function() {
-            this.cancel();
-        }));
-    },
-
-    _getMonitorRect : function (x, y) {
-        let rect = new Meta.Rectangle({ x: x - 1, y: y - 1, width: 1, height: 1 });
-        let monitorIndex = global.screen.get_monitor_index_for_rect(rect);
-
-        return global.screen.get_monitor_geometry(monitorIndex);
-    },
-
-    vfunc_gesture_prepare : function(action, actor) {
-        if (this.get_n_current_points() == 0)
-            return false;
-
-        let [x, y] = this.get_press_coords(0);
-        let monitorRect = this._getMonitorRect(x, y);
-
-        return ((this._side == St.Side.LEFT && x < monitorRect.x + EDGE_THRESHOLD) ||
-                (this._side == St.Side.RIGHT && x > monitorRect.x + monitorRect.width - EDGE_THRESHOLD) ||
-                (this._side == St.Side.TOP && y < monitorRect.y + EDGE_THRESHOLD) ||
-                (this._side == St.Side.BOTTOM && y > monitorRect.y + monitorRect.height - EDGE_THRESHOLD));
-    },
-
-    vfunc_gesture_progress : function (action, actor) {
-        let [startX, startY] = this.get_press_coords(0);
-        let [x, y] = this.get_motion_coords(0);
-        let offsetX = Math.abs (x - startX);
-        let offsetY = Math.abs (y - startY);
-
-        if (offsetX < EDGE_THRESHOLD && offsetY < EDGE_THRESHOLD)
-            return true;
-
-        if ((offsetX > offsetY &&
-             (this._side == St.Side.TOP || this._side == St.Side.BOTTOM)) ||
-            (offsetY > offsetX &&
-             (this._side == St.Side.LEFT || this._side == St.Side.RIGHT))) {
-            this.cancel();
-            return false;
-        }
-
-        return true;
-    },
-
-    vfunc_gesture_end : function (action, actor) {
-        let [startX, startY] = this.get_press_coords(0);
-        let [x, y] = this.get_motion_coords(0);
-        let monitorRect = this._getMonitorRect(startX, startY);
-
-        if ((this._side == St.Side.TOP && y > monitorRect.y + DRAG_DISTANCE) ||
-            (this._side == St.Side.BOTTOM && y < monitorRect.y + monitorRect.height - DRAG_DISTANCE) ||
-            (this._side == St.Side.LEFT && x > monitorRect.x + DRAG_DISTANCE) ||
-            (this._side == St.Side.RIGHT && x < monitorRect.x + monitorRect.width - DRAG_DISTANCE))
-            this.emit('activated');
-    }
-});
-Signals.addSignalMethods(EdgeDragAction.prototype);
-
 const ShowOverviewAction = new Lang.Class({
     Name: 'ShowOverviewAction',
     Extends: Clutter.GestureAction,
@@ -287,7 +217,7 @@ const ViewSelector = new Lang.Class({
 
         let gesture;
 
-        gesture = new EdgeDragAction(St.Side.LEFT);
+        gesture = new EdgeDragAction.EdgeDragAction(St.Side.LEFT);
         gesture.connect('activated', Lang.bind(this, function() {
             if (Main.overview.visible)
                 Main.overview.hide();